from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from utils import load_config


def get_webdriver():
    # 载入配置文件
    conf = load_config()

    options = Options()
    options.add_experimental_option("detach", True)
    # options.add_argument(r'user-data-dir=C:\Users\djs\AppData\Local\Temp\scoped_dir18936_1312634945')
    options.add_argument("--start-maximized")

    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('"--headless"')
    # driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
    driver = webdriver.Remote(command_executor='http://117.78.47.55:5000/wd/hub', options=options)
    driver.implicitly_wait(conf.get('web_settings').get('implicitly_wait'))
    return driver
